package com.mk.wardsystemserver.controller;


import com.mk.wardsystemserver.pojo.Patient;
import com.mk.wardsystemserver.pojo.RespBean;
import com.mk.wardsystemserver.pojo.Salary;
import com.mk.wardsystemserver.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2022-02-24
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;

    @ApiOperation(value="获取所有工资账套")
    @GetMapping("/")
    private List<Salary> getAllSalaries(){
        return salaryService.list();
    }

    @ApiOperation(value="添加工资账套")
    @PostMapping("/")
    private RespBean addSalary(@RequestBody Salary salary){
        salary.setCreateDate(LocalDateTime.now());
        if(salaryService.save(salary)){
            return RespBean.success("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @ApiOperation(value="删除工资套账")
    @DeleteMapping("/{id}")
    private RespBean deleteSalary(@PathVariable Integer id){
        if(salaryService.removeById(id)){
            return RespBean.success("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @ApiOperation(value="更新工资")
    @PutMapping("/")
    private RespBean updateSalary(@RequestBody Salary salary){
        if(salaryService.updateById(salary)){
            return RespBean.success("更新成功!");
        }
        return RespBean.error("更新失败!");
    }
}
